import React from "react";
import { FlatList, Image, ScrollView, StyleSheet, Text } from "react-native";
import { TouchableOpacity, View } from "react-native-ui-lib";
import { commonStyles } from "../../configs/commonStyle";
import navigator from "../../utils/navigator";
import BasePage from "../BasePage";
import ListSeparator from "../common/ListSeparator";
import ListEmpty from "../common/ListEmpty";
import ListFooter from "../common/ListFooter";
import { IconImage } from "../../utils";
import { inject, observer } from "mobx-react";
import ToastUtils from "../../utils/ToastUtils";
import NavigateDialog from "../common/NavigateDialog";
import {
  call,
  checkCameraPermission,
  checkRecordAndStorePermission,
  setClipboardContent,
  uploadError,
} from "../../utils/util";
import { toJS } from "mobx";
import PermissionDialog from "../common/PermissionDialog";
import ConfirmDialog from "../common/ConfirmDialog";
import ModifyDeliveryTimeDialog from "./dialog/ModifyDeliveryTimeDialog";
import moment from "moment";
import { windowWidth } from "../../configs/platform";
import EditMobileDialog from "./dialog/EditMobileDialog";
import { isTest } from "../../configs/config";
import InfoDialog from "../common/dialog/InfoDialog";
import api from "../../net/api";
import ExtractedCodeDialog from '../common/dialog/ExtractedCodeDialog';
import { signOrder } from "../../net/order";

// 优先渠道
const firstChannelList = ['美团外卖', '美团团购', '饿了么', '抖音'];

/**
 * 配送订单
 */
@inject("userStore", "appStore")
@observer
export default class DeliveryOrderList extends BasePage {

  constructor(props) {
    super(props);
    this.pageNo = 1;
    this.pageSize = 15;
    this.totalPages = 0;
    this.isLoading = false;
    this.isFirst = true;
    this.timeLong = 0;
    this.recorder = React.createRef();
    this.player = React.createRef();
    this.data;
    this.codeSelectedItem = {} // 提取码选中的订单
    this.state = {
      isRefreshing: false,
      showFoot: 0,
      showEmpty: false,
      dataList: [],
      delyStartTime: this.props.delyStartTime,
      delyEndTimeEnd: this.props.delyEndTimeEnd,
      recordSecs: 0,
      recordTime: "",
    };
  }

  componentDidMount() {
    super.componentDidMount();
    this.loadData(false);
  }

  loadByDate = (delyStartTime, delyEndTimeEnd) => {
    this.setState({ delyStartTime, delyEndTimeEnd }, () => this._renderRefresh(true));
  };

  loadData(showLoading = false) {
    const { dataList, delyStartTime, delyEndTimeEnd } = this.state;
    const { userInfo } = this.props.userStore;
    if (IsNullOrEmpty(delyStartTime)) {
      uploadError("queryOrder查询日期为空", `${delyStartTime},${delyEndTimeEnd}`);
    }
    this.isLoading = true;
    let params = {
      pageNum: this.pageNo,
      pageSize: this.pageSize,
      token: global.token,
      distributorId: userInfo.distributorId,
      ordState: this.props.value,
      delyStartTime: `${delyStartTime} 00:00:00`,
      delyEndTimeEnd: `${delyEndTimeEnd} 23:59:59`,
      showLoading,
    };
    axios.get(api.queryOrder, { params })
      .then(res => {
        this.isLoading = false;
        // logger("查询结果", JSON.stringify(res));
        let tempArr = [];
        let showf;
        this.totalPages = res.pages;
        if (this.pageNo == 1) {
          tempArr = res.list || [];
          showf = 0;
        } else {
          tempArr = dataList.concat(res.list);
          showf = (this.pageNo == this.totalPages) ? 1 : 0;
        }
        this.setState({
          //复制数据源
          dataList: tempArr.map(item => {
            return {
              ...item,
              deliveryTimeStr: `${item.delyTime || '未知'} ${item.delySTime || '未知'} - ${item.delyETime || '未知'}`
            }
          }),
          showFoot: showf,
          isRefreshing: false,
          showEmpty: (this.pageNo == 1 && tempArr.length == 0 ? true : false),
        });
      })
      .catch(e => {
        logger("error", e);
        this.isLoading = false;
        this.setState({
          isRefreshing: false,
          showEmpty: (this.pageNo == 1 ? true : false),
        });
      });
  }

  _onEndReached = async () => {
    //如果是正在加载中或到底了，则返回
    if (this.state.showFoot != 0) {
      return;
    }
    //如果当前页大于或等于总页数，那就是到最后一页了，返回
    if (this.pageNo == this.totalPages || this.totalPages == 0) {
      return;
    } else {
      this.pageNo++;
    }
    //底部显示正在加载更多数据
    this.setState({ showFoot: 2 });
    //获取数据
    this.loadData();
  };

  // 下拉刷新
  _renderRefresh = (isRefreshing = true) => {
    // 不处于 下拉刷新
    if (this.isLoading === false && !this.state.isRefreshing) {
      this.setState({
        isRefreshing,
      });
      this.pageNo = 1;
      this.totalPages = 0;
      this.loadData(isRefreshing);
      this.props.refresh();
    }
  };

  clickRecord = async (item) => {
    const { recordingNo, playingNo, setValue } = this.props.userStore;
    let isPlaying = item.xmbzNo == playingNo;
    if (isPlaying) {
      // await this.player.current.stop();
      setValue("playingNo", "");
      setValue("showPlayer", "");
      setValue("showPage", "");
    }
    if (!IsNullOrEmpty(recordingNo)) {
      ToastUtils.showInfo("请先停止录音");
      return;
    }
    let permission = await checkRecordAndStorePermission();
    if (permission) {
      setValue("recordingNo", item.xmbzNo);
      setValue("showRecorder", true);
      setValue("showPage", "main");
      // setTimeout(() => this.recorder.current.startRecord(), 500);
    } else {
      this.permissionDialog.show("录音需要麦克风和存储权限，请开启");
    }
  };

  getRecordText = (data, reRecord) => {
    const { uploadFailList } = this.props.userStore;

    const record = uploadFailList && uploadFailList.find(item => item.recordingNo == data.xmbzNo);
    if (record) {
      return (
        <View centerH>
          <Image source={IconImage.icon_uploading} style={styles.btn_icon} />
          <Text style={commonStyles.text_black_12}>上传中</Text>
        </View>
      );
    } else {
      if (reRecord) {
        return (
          <TouchableOpacity activeOpacity={1} centerH throttleTime={1000} onPress={() => {
            this.data = data;
            this.confirmDialog.show("执行该操作会清除现有录音记录，您确定要重新录音吗?");
          }}>
            <Image source={IconImage.btn_re_record} style={styles.btn_icon} />
            <Text style={commonStyles.text_black_12}>重录</Text>
          </TouchableOpacity>
        );
      }
      return (
        <TouchableOpacity centerH activeOpacity={1} throttleTime={1000}
                          onPress={() => this.clickRecord(data)}>

          <Image source={IconImage.btn_record} style={styles.btn_icon} />
          <Text style={commonStyles.text_black_12}>录音</Text>
        </TouchableOpacity>
      );
    }
  };

  render_item = ({ item, index }) => {
    const danceLabelMap = {
      0: '不跳舞',
      1: '跳舞',
      2: '-',
    }
    return (
      <View marginB-10>
        <View style={styles.titleWrap}>
          <TouchableOpacity flex activeOpacity={1} onPress={() => setClipboardContent(item?.xmbzNo)}>
            <Text style={commonStyles.text_black_14}>单号：{item?.xmbzNo}</Text>
          </TouchableOpacity>
          {
            firstChannelList.includes(item.chanName) ? 
            (<View row center>
              <Image source={IconImage.icon_fire}
                            style={{ width: 20, height: 20, marginRight: 4 }} />
              <Text style={{color: '#d81e06', fontSize: 14}}>三方 - {item.chanName}</Text>
            </View>) : null
          }
        </View>
        <View style={styles.contentWrap}>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>配送时间</Text>
            <TouchableOpacity activeOpacity={1} onPress={() => this.infoDialog.show(`配送时间：${item.deliveryTimeStr}`)}>
              <Text style={commonStyles.text_black_13}>{item.deliveryTimeStr}</Text>
            </TouchableOpacity>
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>状态</Text>
            <Text style={commonStyles.text_blue_13}>{item?.ordStateName}</Text>
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>收货人</Text>
            <Text style={commonStyles.text_black_13}>{item?.cneeName}</Text>
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>分仓</Text>
            <Text style={commonStyles.text_black_13}>{item?.invoiceHeader}</Text>
          </View>
          {/* <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>跳舞属性</Text>
            <Text style={commonStyles.text_black_13}>{item ? danceLabelMap[item.isDance] : '-'}</Text>
          </View> */}
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>下单电话</Text>
            {
              item.bookTelNo && !item.bookTelNo.includes("*") ?
                <TouchableOpacity onPress={() => call(item?.bookTelNo,item?.ordNo)}>
                  <Text style={commonStyles.text_black_13}>{item?.bookTelNo}</Text>
                </TouchableOpacity>
                : <Text style={commonStyles.text_black_13}>{item?.bookTelNo}</Text>
            }
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>联系电话</Text>
            {
              item.cneeTel && !item.cneeTel.includes("*") ?
                <TouchableOpacity onPress={() => call(item?.cneeTel,item?.ordNo)}>
                  <Text style={commonStyles.text_black_13}>{item?.cneeTel}</Text>
                </TouchableOpacity>
                : <Text style={commonStyles.text_black_13}>{item?.cneeTel}</Text>
            }
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>地址</Text>
            <TouchableOpacity activeOpacity={1} marginL-10 flex right onPress={() => {
              if (item.addressLng == 0 || item.addressLat == 0) {
                ToastUtils.showInfo("地址无定位数据");
                return;
              }
              navigator.navigate("OrderLocate", { data: item });
            }}>
              <Text style={commonStyles.text_black_13}>{item?.address1}</Text>
            </TouchableOpacity>
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>备注</Text>
            <Text style={commonStyles.text_black_13}>{item?.delyNeeds}</Text>
          </View>
          {
            item.orderDetailList && item.orderDetailList.some(item => item.tyingRefundContent) ? 
            (<View style={styles.itemWrap}>
              <Text style={commonStyles.text_black_13}>搭售退单说明</Text>
              <Text style={commonStyles.text_red_13}>下拉查看退货详情</Text>
            </View>) : null
          }
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>渠道</Text>
            <Text style={commonStyles.text_black_13}>{item?.chanName}</Text>
          </View>
          <View style={styles.itemWrap}>
            <Text style={commonStyles.text_black_13}>扫码关注</Text>
            <Text style={commonStyles.text_black_13}>{item.tag == '1' ? '需要' : '不需要'}</Text>
          </View>
          { this.render_item_question(item) }
          { this.render_item_goods(item) }
        </View>
        <View style={styles.line} />
        { this.render_item_footer(item) }
      </View>
    );
  };

  // 惊喜收集信息
  render_item_question = (item) => {
    return (<View>
      {
        item.questionRelation ?
        <View style={styles.itemWrap}>
          <Text style={commonStyles.text_black_13}>希望将惊喜送给</Text>
          <Text style={commonStyles.text_black_13}>{item?.questionRelation}</Text>
        </View> : null
      }
      {
        item.questionSex ?
        <View style={styles.itemWrap}>
          <Text style={commonStyles.text_black_13}>收货人的性别</Text>
          <Text style={commonStyles.text_black_13}>{item?.questionSex}</Text>
        </View> : null
      }
      {
        item.questionAtmosphere ?
        <View style={styles.itemWrap}>
          <Text style={commonStyles.text_black_13}>期待的气氛</Text>
          <Text style={commonStyles.text_black_13}>{item?.questionAtmosphere}</Text>
        </View> : null
      }
      {
        item.questionPlace ?
        <View style={styles.itemWrap}>
          <Text style={commonStyles.text_black_13}>小熊猫出现的场景是</Text>
          <Text style={commonStyles.text_black_13}>{item?.questionPlace}</Text>
        </View> : null
      }
    </View>)
  }

  render_item_goods = (item) => {
    return (<View style={{ paddingVertical: 6 }}>
      {
        item.orderDetailList && item.orderDetailList.map(data => {
          return (
            <View row marginT-5>
              <Image source={data.isScan == 0 ? IconImage.ic_unchecked : IconImage.ic_checked}
                     style={{ width: 17, height: 17, marginRight: 5 }} />
              <View flex>
                <Text style={commonStyles.text_black_13}>
                    {data?.goodsName}（{data?.goodsSpecs}）（x{data?.num}）
                    {
                      data?.goodsName && data?.goodsName.includes('配送费') ?
                      <Text>（{data?.totalPrice / 100}元）</Text> : null
                    }
                </Text>
                {
                  data?.tyingRefundContent ? 
                  <Text style={commonStyles.text_red_14}>{`已退商品：${data.tyingRefundContent}`}</Text> : null
                }
              </View>
            </View>
          );
        })
      }
    </View>)
  }

  render_item_footer = (item) => {
    const { recordingNo, playingNo, setValue, topList } = this.props.userStore;
    let isRecording = item.xmbzNo == recordingNo;
    let isPlaying = item.xmbzNo == playingNo;
    const { userInfo } = this.props.userStore;

    let allChecked = true;
    if (!IsNullOrEmpty(item.orderDetailList) && item.orderDetailList.find(data => data.isScan == 0)) {
      allChecked = false;
    }

    return (<View style={{}} >
      <ScrollView horizontal showsHorizontalScrollIndicator={false} style={{width:windowWidth-30,alignSelf:'center',backgroundColor:'white'}} >
      <View style={styles.btnWrap}>
        <View style={styles.btnItem}>
          <TouchableOpacity centerH activeOpacity={1} throttleTime={1000} onPress={() => {
            let list = toJS(topList);
            list = [item.ordNo, ...list.filter(data => data != item.ordNo)];
            logger("置顶", list);
            setValue("topList", list);
          }}>
            <Image source={IconImage.btn_top} style={styles.btn_icon} />
            <Text style={commonStyles.text_black_12}>置顶</Text>
          </TouchableOpacity>
        </View>
        {
          item.ordState == 7 || item.ordState == 9 || item.ordState == 8 || item.ordState == 12 ? null :
          <View flex row>
            <View style={styles.btnItem}>
              <TouchableOpacity
                centerH
                onPress={async () => {
                  // if (GLOBAL.__DEV__) {
                  //   navigator.navigate("OrderDetails", { from: 'orderList', ordNo: item.ordNo })
                  //   return
                  // }
                  let permission = await checkCameraPermission();
                  if (permission) {
                    navigator.navigate("ScanPage", { from: "orderList", ordNo: item.ordNo });
                  } else {
                    this.permissionDialog.show("扫描订单需要获得相机使用权限，请开启");
                  }
                }}
                activeOpacity={1} throttleTime={1000}
              >
                <Image source={IconImage.btn_scan} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>扫描</Text>
              </TouchableOpacity>
            </View>
            <View style={styles.btnItem}>
              <TouchableOpacity
                centerH
                onPress={() => {
                  this.codeSelectedItem = item
                  this.extractedCodeDialog.show('提取码取件')
                }}
                activeOpacity={1} throttleTime={1000}
              >
                <Image source={IconImage.btn_tiqu} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>提取码</Text>
              </TouchableOpacity>
            </View>
          </View>
        }
        {
          (item.addressLng == 0 || item.addressLat == 0) ? null :
            <View style={styles.btnItem}>
              <TouchableOpacity centerH onPress={() => this.navigate(item)} activeOpacity={1} throttleTime={1000}>
                <Image source={IconImage.btn_navigation} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>导航</Text>
              </TouchableOpacity>
            </View>
        }
        {
          item.ordState == 7 ?
            <View style={styles.btnItem}>
              <TouchableOpacity centerH onPress={() => {
                if (item.datediff <= 0) {
                  this.data = item;
                  this.signConfirmDialog.show("确定要签收吗？");
                }
              }} activeOpacity={1} throttleTime={1000}
              >
                <Image source={item.datediff > 0 ? IconImage.btn_un_signfor : IconImage.btn_signfor}
                       style={styles.btn_icon} />
                <Text style={item.datediff > 0 ? commonStyles.text_gray_12 : commonStyles.text_black_12}>签收</Text>
              </TouchableOpacity>
            </View>
            : null
        }

        {
          item.ordState == 8 || item.ordState == 9 ? null :
            <View style={styles.btnItem}>
              <TouchableOpacity centerH activeOpacity={1} throttleTime={1000}
                                onPress={() => navigator.navigate("DeliveryException", { ...item })}
              >
                <Image source={IconImage.btn_exception} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>异常</Text>
              </TouchableOpacity>
            </View>
        }

        {
          item.ordState == 6 && allChecked == true ?
            <View style={styles.btnItem}>
              <TouchableOpacity centerH onPress={() => this.deliveryOrder(item)} activeOpacity={1} throttleTime={1000}
              >
                <Image source={IconImage.btn_delivery} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>配送</Text>
              </TouchableOpacity>
            </View>
            : null
        }
        {
          item.ordState == 6 || item.ordState == 7 ?
            <View style={styles.btnItem}>
              <TouchableOpacity centerH onPress={() => this.modifyDeliveryTimeDialog.show(item)} activeOpacity={1}
                                throttleTime={1000}
              >
                <Image source={IconImage.btn_delivery_modify} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>配送修改</Text>
              </TouchableOpacity>
            </View>
            : null
        }
        {
          item.ordState == 8 || item.ordState == 9 ? null :
          <View style={styles.btnItem}>
            <TouchableOpacity centerH onPress={() => {
              navigator.navigate('ModifyOrder', {order: item})
            }} activeOpacity={1} throttleTime={1000}>
                <Image source={IconImage.btn_delivery_modify} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>修改订单</Text>
            </TouchableOpacity>
          </View>
        }
        {
          IsNullOrEmpty(item.recordPath) && !isRecording && (item.ordState == 7 || item.ordState == 8) && item.datediff <= 1 ?
            <View style={styles.btnItem}>
              {this.getRecordText(item, false)}
            </View>
            : null
        }
        {
          !IsNullOrEmpty(item.recordPath) && !isRecording && item.datediff <= 1 ? <View style={styles.btnItem}>
              {this.getRecordText(item, true)}
            </View>
            : null
        }
        {
          !IsNullOrEmpty(item.recordPath) && !isPlaying ?
            <View style={styles.btnItem}>
              <TouchableOpacity centerH activeOpacity={1} onPress={() => {
                if (isRecording) {
                  ToastUtils.showFailInfo("正在录音，不能播放");
                  return;
                }
                if (isPlaying == false) {
                  setValue("playingNo", item.xmbzNo);
                  setValue("showPlayer", item.recordPath);
                  setValue("showPage", "main");
                  // setTimeout(() => this.player.current.play(item.recordPath), 500);
                }
              }}>
                <Image source={IconImage.btn_play} style={styles.btn_icon} />
                <Text style={commonStyles.text_black_12}>播放</Text>
              </TouchableOpacity>
            </View>
            : null
        }
        {/*<View style={styles.btnItem}>*/}
        {/*  <TouchableOpacity marginR-15  centerH onPress={() => this.editMobileDialog.show(item?.ordNo)} activeOpacity={1}>*/}
        {/*    <Image source={IconImage.btn_delivery_modify} style={styles.btn_icon} />*/}
        {/*    <Text style={commonStyles.text_black_12}>修改手机</Text>*/}
        {/*  </TouchableOpacity>*/}
        {/*</View>*/}
      </View>
      </ScrollView>
      </View>)
  }

  /**
   * 签收
   */
  signOrder = (item) => {
    const { location } = this.props.userStore;
    signOrder({
        ordNo: item.ordNo,
        showLoading: true,
        token: global.token,
        longitude: location.longitude,
        latitude: location.latitude,
        altitude: location.altitude || 60,
    }).then(result => {
        ToastUtils.showSuccessInfo("签收成功");
        this._renderRefresh(false);
        if (result.code !== 200) {
          uploadError(`调用签收接口失败：${api.signOrder}`,`单号：${item.ordNo}\n, ${JSON.stringify(result)}`)
        }
      }).catch((e) => {
      logger(e);
      e.msg && ToastUtils.showFailInfo(e.msg + `:${location.longitude},${location.latitude}`);
    });
  };

  /**
   * 立即配送
   * @param item
   */
  deliveryOrder = (item) => {
    axios.get(api.deliveryOrder, {
      params: {
        ordNo: item.ordNo,
        showLoading: true,
        token: global.token,
      },
    })
      .then(result => {
        ToastUtils.showSuccessInfo("提交成功");
        this._renderRefresh(false);
      }).catch((e) => {
      logger(e);
      e.msg && ToastUtils.showFailInfo(e.msg);
    });
  };

  /**
   * 申请修改配送时间
   * @param item
   */
  updateDeliveryTimePre = (item, timer) => {
    logger("申请修改配送时间", item?.ordNo, timer);
    let params = {
      ordNo: item?.ordNo,
      showLoading: true,
    };
    if (timer?.startTime == 23) {
      params["startTime"] = `${moment().format("YYYY-MM-DD ")}${timer?.startTime}:00:00`;
      params["endTime"] = `${moment().format("YYYY-MM-DD ")}23:59:59`;
    } else {
      params["startTime"] = `${moment().format("YYYY-MM-DD ")}${timer?.startTime}:00:00`;
      params["endTime"] = `${moment().format("YYYY-MM-DD ")}${timer?.endTime}:00:00`;
    }
    axios.get(api.updateDeliveryTimePre, {
      params,
    })
      .then(result => {
        ToastUtils.showSuccessInfo("提交成功");
        this._renderRefresh(false);
      }).catch((e) => {
      logger(e);
      e.msg && ToastUtils.showFailInfo(e.msg);
    });
  };

  updateMobile = (ordNo,phone) => {
    let params = {
      ordNo,
      phone,
      showLoading: true,
    };

    axios.get(api.updatePrivacy, {
      params,
    })
      .then(result => {
        ToastUtils.showSuccessInfo("修改成功");
        this._renderRefresh(false);
      }).catch((e) => {
      logger(e);
      e.msg && ToastUtils.showFailInfo(e.msg);
    });
  };

  navigate = (item) => {
    if (item.addressLng == 0 || item.addressLat == 0) {
      ToastUtils.showFailInfo("配送定位为空，请联系管理员");
      return;
    }
    this.navigateDialog.show({
      latitude: item.addressLat,
      longitude: item.addressLng,
    }, item.address1);
  };

  // 提取码处理
  handleCodeConfirm = (result) => {
    const { orderDetailId, orderId } = result
    if (!orderDetailId || !orderId) {
      ToastUtils.showFailInfo('提取码解析失败，请重试');
      return
    }
    if (this.codeSelectedItem.ordNo != orderId) {
      ToastUtils.showFailInfo("拿错蛋糕了，请仔细检查");
      return;
    }
    const { userInfo } = this.props.userStore;
    const params = {
      token: global.token,
      distributorId: userInfo.distributorId,
      orderDetailId,
      orderId,
      scanTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      showLoading: true,
    }
    return axios.get(api.addDeliveryScanLog, { params })
      .then(res => {
        if (orderId && orderId != res.result.ordNo) {
          ToastUtils.showFailInfo("拿错蛋糕了，请仔细检查");
          return;
        }

        ToastUtils.showSuccessInfo("提取成功");
        this._renderRefresh(false);
      }).catch(e => {
        e.msg && ToastUtils.showFailInfo(e.msg);
        uploadError("提取码调用addDeliveryScanLog失败", `参数：${JSON.stringify(params)},${e.msg}`);
      })
  }

  render() {
    const { dataList, isRefreshing } = this.state;
    const { topList, recordingNo, playingNo, uploadFailList } = this.props.userStore;
    // logger("更新", recordingNo, playingNo, uploadFailList);
    let tempArr = dataList;
    if (!IsNullOrEmpty(toJS(topList))) {
      let top = [];
      topList.map(item => {
        const temp = dataList.filter(data => data.ordNo == item);
        if (!IsNullOrEmpty(temp)) {
          top.push(temp[0]);
        }
      });
      // logger("更新置顶2", top);
      let unTop = dataList.filter(data => !toJS(topList).includes(data.ordNo));
      tempArr = [...top, ...unTop];
    }
    return (
      <View flex>
        <FlatList
          data={tempArr}
          onRefresh={this._renderRefresh}
          showsVerticalScrollIndicator={false}
          refreshing={isRefreshing}
          extraData={this.state}
          style={{}}
          contentContainerStyle={{ flexGrow: 1 }}
          keyExtractor={(item, index) => "menu_" + index}
          renderItem={this.render_item}
          ItemSeparatorComponent={() => <ListSeparator height={0.5} backgroundColor={"#F7F7F7"} />}
          ListEmptyComponent={() => <ListEmpty showEmpty={this.state.showEmpty} />}
          onEndReached={this._onEndReached}
          onEndReachedThreshold={0.1}
          ListFooterComponent={() => <ListFooter showFoot={this.state.showFoot} page={this.pageNo} />}
        />
        <NavigateDialog ref={r => this.navigateDialog = r} />
        <PermissionDialog ref={r => this.permissionDialog = r} />
        <ConfirmDialog ref={r => this.confirmDialog = r} callBack={() => this.clickRecord(this.data)} />
        <ConfirmDialog ref={r => this.signConfirmDialog = r} callBack={() => this.signOrder(this.data)} />
        <ModifyDeliveryTimeDialog ref={r => this.modifyDeliveryTimeDialog = r} callBack={this.updateDeliveryTimePre} />
        <EditMobileDialog ref={r => this.editMobileDialog = r} callBack={this.updateMobile} />
        <InfoDialog ref={r => this.infoDialog = r} />
        <ExtractedCodeDialog 
          ref={r => (this.extractedCodeDialog = r)}
          callBack={this.handleCodeConfirm}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  titleWrap: {
    flexDirection: "row",
    alignItems: "center",
    borderTopLeftRadius: 4,
    borderTopRightRadius: 4,
    backgroundColor: "#F9D63B",
    marginHorizontal: 15,
    paddingHorizontal: 15,
    paddingVertical: 10,
  },
  contentWrap: {
    backgroundColor: "white",
    marginHorizontal: 15,
    paddingHorizontal: 15,
    paddingVertical: 10,
  },
  itemWrap: {
    justifyContent: "space-between",
    flexDirection: "row",
    alignItems: "center",
    paddingVertical: 6,
    width: '98%',
    flexWrap: 'wrap',
  },
  line: {
    height: 1,
    backgroundColor: "#EFEFEF",
    marginHorizontal: 15,
  },
  btnWrap: {
    flexDirection: "row",
    alignItems: "center",
    backgroundColor: "white",
    paddingVertical: 5,
  },
  btnItem: { ...commonStyles.center,marginLeft:15, },
  btn_icon: { width: 43, height: 43, marginBottom: 3 },
});
